package com.cskaoyan.shopping.service.remote;

import com.cskaoyan.mall.api.OrderProductService;
import com.cskaoyan.mall.commons.result.ResponseUtil;
import com.cskaoyan.mall.constant.ShoppingRetCode;
import com.cskaoyan.mall.dto.ClearCartItemRequest;
import com.cskaoyan.mall.dto.ClearCartItemResponse;
import com.cskaoyan.mall.dto.ProductDetailRequest;
import com.cskaoyan.mall.dto.ProductDetailResponse;
import com.cskaoyan.shopping.service.ICartService;
import com.cskaoyan.shopping.service.IProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @auther cskaoyan
 * @date 2022/5/18:10:21
 */
@RestController
public class OrderProductServiceImpl implements OrderProductService {


    @Autowired
    ICartService iCartService;

    @Autowired
    IProductService productService;

    /**
     * 清空指定用户的购物车缓存(用户下完订单之后清理）
     */
    @RequestMapping(value = "/rpc/items",method = RequestMethod.DELETE)
    @Override
    public ClearCartItemResponse clearCartItemByUserID(@RequestBody ClearCartItemRequest request) {

        ClearCartItemResponse response = iCartService.clearCartItemByUserID(request);
        if (response.getCode().equals(ShoppingRetCode.SUCCESS.getCode())) {
            return response;
        }
        return null;
    }

    @PostMapping("rpc/detail")
    @Override
    public ProductDetailResponse getProductDetail(ProductDetailRequest request) {
        return productService.getProductDetail(request);
    }
}
